﻿using AuthCenter_HuangJingtao.Domain;
using AuthCenter_HuangJingtao.ErrorCode;
using AuthCenter_HuangJingtao.Infrastructure.Imterfaces;
using AuthCenter_HuangJingtao.Read.Api.Application.Command.ReversoaLL;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace AuthCenter_HuangJingtao.Read.Api.Application.CommandHandler.ReversoaLL
{
    public class FirstReversoCommandHandler : IRequestHandler<FirstReversoCommand, ApiResult<Reverso>>
    {
        IBaseReponsitory<Reverso> Reverso;

        public FirstReversoCommandHandler(IBaseReponsitory<Reverso> Reverso)
        {
            this.Reverso = Reverso;
        }

        public async Task<ApiResult<Reverso>> Handle(FirstReversoCommand request, CancellationToken cancellationToken)
        {
            var list = await Reverso.GetQuery().FirstOrDefaultAsync(c => c.Reverso_Id == request.id);
            return new ApiResult<Reverso>
            {
                Code = ApiEnum.Success,
                Message = "查询成功",
                Data = list
            };
        }  
    }
}
